home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / CBRMNDX.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  100 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbrmndx.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STDDEF
  11. #include <stddef.h>
  12. #endif
  13.  
  14. /* library headers */
  15. #include <btree.h>
  16.  
  17. /* local headers */
  18. #include "cbase_.h"
  19.  
  20. /*man---------------------------------------------------------------------------
  21. NAME
  22.      cbrmndx - remove cbase index
  23.  
  24. SYNOPSIS
  25.      #include <cbase.h>
  26.  
  27.      int cbrmndx(cbp, field)
  28.      cbase_t *cbp;
  29.      int field;
  30.  
  31. DESCRIPTION
  32.      The cbrmndx function deletes an existing cbase index.  The field
  33.      whose index is to be deleted for cbp is specified by field.
  34.  
  35.      cbrmndx will fail if one or more of the following is true:
  36.  
  37.      [CBELOCK]      cbp is not write-locked.
  38.      [ENOENT]       The named field is not a key.
  39.      [ENOENT]       The named field's index file does not exist.
  40.      [EINVAL]       cbp is not a valid cbase pointer.
  41.      [EINVAL]       field is not a valid field number for cbp.
  42.  
  43. SEE ALSO
  44.      cbcreate, cbmkndx.
  45.  
  46. DIAGNOSTICS
  47.      Upon successful completion, a value of 0 is returned.  Otherwise,
  48.      a value of -1 is returned, and errno set to indicate the error.
  49.  
  50. ------------------------------------------------------------------------------*/
  51. #ifdef AC_PROTO
  52. int cbrmndx(cbase_t *cbp, int field)
  53. #else
  54. int cbrmndx(cbp, field)
  55. cbase_t *cbp;
  56. int field;
  57. #endif
  58. {
  59.     /* validate arguments */
  60.     if (!cb_valid(cbp)) {
  61.         errno = EINVAL;
  62.         return -1;
  63.     }
  64.     if (field < 0 || field >= cbp->fldc) {
  65.         errno = EINVAL;
  66.         return -1;
  67.     }
  68.  
  69.     /* check lock status */
  70.     if (cbgetlck(cbp) != CB_WRLCK) {
  71.         errno = CBELOCK;
  72.         return -1;
  73.     }
  74.  
  75.     /* check if not an index */
  76.     if (!(cbp->fldv[field].flags & CB_FKEY)) {
  77.         errno = ENOENT;
  78.         return -1;
  79.     }
  80.  
  81.     /* close btree */
  82.     if (btclose(cbp->btpv[field]) == -1) {
  83.         CBEPRINT;
  84.         return -1;
  85.     }
  86.     cbp->btpv[field] = NULL;
  87.  
  88.     /* delete index file */
  89.     if (remove(cbp->fldv[field].filename)) {
  90.         CBEPRINT;
  91.         return -1;
  92.     }
  93.  
  94.     /* disable old index */
  95.     cbp->fldv[field].flags &= !(CB_FFLAGS);
  96.     cbp->fldv[field].filename = NULL;
  97.  
  98.     return 0;
  99. }
  100.